<?php
    /*
      Klenwell Wikka Template Header

    */

    # init
    $css_screen_file = 'klenwell.css';
    $this_page_title = $this->PageTitle();
    $redirect_message = $this->GetRedirectMessage();
    $user = $this->GetUser();
    $site_base = $this->GetConfigValue("base_url");
    $site_base = ( substr_count($site_base, 'wikka.php?wakka=') > 0 )
        ? substr($site_base,0,-16)
        : $site_base;

    $rss_linkf = '<link rel="alternate" type="application/rss+xml" title="%s" href="%s" />';

    # universal edit button (http://universaleditbutton.org/Universal_Edit_Button) #779
    $ueb = '';
    if ( $this->GetHandler() != 'edit'
        && $this->HasAccess("write", $this->page["tag"]) )
    {
        $uebf = '<link rel="%s" type="%s" title="%s" href="%s" />';
        $ueb = sprintf( $uebf,
                        'alternate',
                        'application/x-wiki',
                        sprintf('Click to edit %s', $this->page["tag"]),
                        $this->Href('edit', $this->page["tag"]) );
    }

    # no follow tag
    if ( $this->GetHandler() != 'show' || $this->page["latest"] == 'N' ||
         $this->page["tag"] == 'SandBox')
    {
        $head_robots = '<meta name=\"robots\" content=\"noindex, nofollow, noarchive\" />';
    }
    else
    {
        $head_robots = '<!-- robots welcome! -->';
    }

    # rss links
    if ($this->GetHandler() != 'edit')
    {
        $rss_link1 = sprintf($rss_linkf,
                             sprintf('%s: revisions for %s (RSS)',
                                     $this->GetWakkaName(),
                                     $this->tag),
                             $this->Href('revisions.xml', $this->tag) );
        $rss_link2 = sprintf($rss_linkf,
                             sprintf('%s: recently edited pages (RSS)',
                                     $this->GetWakkaName() ),
                             $this->Href('recentchanges.xml', $this->tag) );
    }
    else
    {
        $rss_link1 = $rss_link2 = '';
    }

    # additional headers
    if ( isset($this->additional_headers) && is_array($this->additional_headers)
         && count($this->additional_headers) )
    {
        foreach ( $this->additional_headers as $additional_header ) {
	    $AdditionalHeaders[] =  $additional_header;
	}
    }
    else
    {
        $AdditionalHeaders = array();
    }
    $additonal_headers = implode("\n    ", $AdditionalHeaders);

    # head tags
    $head_title = sprintf('<title>%s : %s</title>',
                          $this->GetWakkaName(),
                          $this_page_title );
    $head_base = sprintf('<base href="%s" />', $site_base);
    $meta_generator = sprintf('<meta name="generator" content="%s" />',
                              'WikkaWiki');
    $meta_content_type = sprintf('<meta http-equiv="Content-Type" content="%s" />',
                                 'text/html; charset=iso-8859-1');
    $meta_keywords = sprintf('<meta name="keywords" content="%s" />',
        $this->htmlspecialchars_ent($this->GetConfigValue("meta_keywords")) );
    $meta_description = sprintf('<meta name="description" content="%s" />',
        $this->htmlspecialchars_ent($this->GetConfigValue("meta_description")) );
    $css_screen = sprintf('<link rel="stylesheet" type="text/css" href="%s" />',
        sprintf('%s/css/%s?%s',
                $this->GetThemePath('/'),
                $css_screen_file,
                $this->htmlspecialchars_ent($this->GetConfigValue('stylesheet_hash')) ));
    $css_print = sprintf('<link rel="stylesheet" type="text/css" href="%s/css/print.css" media="print" />',
                         $this->GetThemePath('/') );
    $favicon = sprintf('<link rel="icon" href="%s/images/favicon.ico" type="%s" />',
                       $this->GetThemePath('/'),
                       'image/x-icon');
    $favicon_shortcut = sprintf('<link rel="shortcut icon" href="%s/images/favicon.ico" type="%s" />',
                       $this->GetThemePath('/'),
                       'image/x-icon');
    $google_font_api = ( $this->page["tag"] != 'CssGoogleFonts' ) ? '' :
        '<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Cantarell|Cardo|Crimson+Text|Droid+Sans|Droid+Sans+Mono|Droid+Serif|Inconsolata|Lobster|Molengo|Nobile|Reenie+Beanie|Tangerine|Vollkorn|Josefin+Sans+Std+Light|OFL+Sorts+Mill+Goudy+TT|Old+Standard+TT|IM+Fell+DW+Pica|IM+Fell+English|Yanone+Kaffeesatz" />';

    # templates
    $doctypef = <<<XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
XHTML;

    $headf = <<<XHTML
<head>
    $head_title
    $head_base
    $head_robots
    $meta_generator
    $meta_content_type
    $meta_keywords
    $meta_description

    <!-- stylesheets -->
    $css_screen
    $css_print

    <!-- google font api -->
    $google_font_api

    $favicon
    $favicon_shortcut

    $rss_link1
    $rss_link2

    $additonal_headers

    <!-- google jquery -->
    <script src="http://www.google.com/jsapi"></script>
    <script>
        google.load("jquery", "1.4.2");
        google.load("jqueryui", "1.8.1");
    </script>

    <!-- universal edit button -->
    $ueb
</head>
XHTML;

    $bodyf = <<<XHTML
<body>
    <div id="page">
        <!-- redirect message --> %s

        <div id="header">
            <h2>
                <a id="homepage_link" href="%s">%s</a> :
                <a id="backlinks_link" href="%s" title="%s">%s</a>
            </h2>
        </div>

        <!-- navbar -->
        <div id="navbar">
            %s
            %s
        </div>

        <!-- admin navbar -->
        %s

<!-- end wikka header -->

XHTML;

    # output
    printf($doctypef);
    printf($headf);
    printf($bodyf,
           ( $redirect_message )
              ? sprintf('<div id="redirect_message">%s</div>', $redirect_message)
              : '',
           $this->href('', $this->config['root_page'], ''),
           $this->config['wakka_name'],
           $this->href('backlinks', '', ''),
           sprintf('Display a list of pages linking to %s', $this->tag),
           $this->GetPageTag(),
           $this->MakeMenu('search_menu'),
           $this->MakeMenu('main_menu'),
           ( $this->IsAdmin() ) ? $this->MakeMenu('admin_menu') : '');
